<div class="layui-fluid layui-anim website-anim" id="website-distributeExpert" lay-title="专家管理">
    <div class="layui-row website-container">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body website-table-full">
                    <form class="layui-form layui-table-form" lay-filter="distributeExpert-table-form">
                        <div class="layui-row">
                            <div class="layui-col-md8">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">关键词</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="name" autocomplete="off" class="layui-input"
                                                   placeholder="请输入专家姓名/所在单位">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">学科分类</label>
                                        <div class="layui-input-inline">
                                            <select name="subjectTypeCode">
                                                <option value="">请选择</option>
                                                <option
                                                        th:each="item : ${subjectTypeList}"
                                                        th:value="${item.code}" th:text="${item.name}">
                                                </option>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md4 layui-col-sm12 layui-col-xs12 table-action-area">
                                <input id="reportId" type="hidden" th:value="${reportId}"/>
                                <div class="layui-btn layui-btn-sm layui-btn-primary website-button-blue-plain table-action"
                                     id="query">
                                    查询
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary website-button-green-plain table-action"
                                     id="reset">
                                    重置
                                </div>

                            </div>
                        </div>
                    </form>
                    <table lay-filter="distributeExpertTable" lay-data="{id: 'distributeExpertTable'}"></table>
                    <div class="layui-form-item website-hide">
                        <button class="layui-btn" lay-submit="" lay-filter="distribute-expert-submit"
                                id="submit"></button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="distributeExpert-class">
    {{#
    var dict=layui.dict.getByCode(d.subjectTypeCode);
    }}
    {{#  if(dict){ }}
    <span>{{ dict.name }}</span>
    {{#  } }}
</script>
<script type="text/html" id="distributeExpert-position">
    {{#
    var dict=layui.dict.getByCode(d.positionTypeCode);
    }}
    {{#  if(dict){ }}
    <span>{{ dict.name }}</span>
    {{#  } }}
</script>

<script data-th-inline="none" type="text/javascript">
    layui.use(['dropdown', 'jquery', 'form', 'table', 'website', 'dict'], function () {
        var $ = layui.jquery,
            website = layui.website,
            form = layui.form,
            table = layui.table,
            $view = $('#website-distributeExpert'),
            $query = $view.find('#query'),
            $reset = $view.find('#reset'),
            $searchForm = $view.find('form'),
            sortObject = {field: 'createTime', type: null},
            tableIns,
            createTimeFrom,
            createTimeTo;

        form.render();
        initTable();


        form.on('submit(distribute-expert-submit)', function () {
            var selectData = layui.table.checkStatus('distributeExpertTable').data;
            if (!selectData.length) {
                website.alert.warn('请选择需要分配的专家');
                return false;
            }
            website.post(ctx + 'biz/report/distributeExpert/' + $("#reportId").val(), {expertId: selectData[0].expertId}, function () {
                layer.closeAll();
                website.alert.success('分配专家成功');
                $('#website-report').find('#query').click();
            });
            return false;
        });

        table.on('sort(distributeExpertTable)', function (obj) {
            sortObject = obj;
            tableIns.reload({
                initSort: obj,
                where: $.extend(getQueryParams(), {
                    field: obj.field,
                    order: obj.type
                })
            });
        });
        $query.on('click', function () {
            var params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
            tableIns.reload({where: params, page: {curr: 1}});
        });

        $reset.on('click', function () {
            $searchForm[0].reset();
            sortObject.type = 'null';
            createTimeTo = null;
            createTimeFrom = null;
            tableIns.reload({where: getQueryParams(), page: {curr: 1}, initSort: sortObject});
        });

        function initTable() {
            tableIns = website.table.init({
                elem: $view.find('table'),
                id: 'distributeExpertTable',
                url: ctx + 'expert/list',
                cols: [[
                    {type: 'radio'},
                    {field: 'name', title: '专家姓名', minWidth: 100},
                    {title: '学科分类', templet: '#distributeExpert-class'},
                    {field: 'company', title: '所在单位'},
                    {title: '行政职位', templet: '#distributeExpert-position'},
                    {field: 'phone', title: '联系电话', minWidth: 100},
                    {field: 'address', title: '通讯地址', minWidth: 150}
                ]],
                where: {isPublish: "true"},

            });
        }

        function getQueryParams() {
            var params = $searchForm.serializeJson();
            var createTime = params.time;
            if (createTime) {
                createTimeFrom = createTime.split(' - ')[0];
                createTimeTo = createTime.split(' - ')[1];
            }
            params.invalidate_ie_cache = new Date();
            params.createTimeFrom = createTimeFrom;
            params.createTimeTo = createTimeTo;
            return params;
        }


        layui.table.on('row(distributeExpertTable)', function (obj) {
            //选中行样式
            obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');
            //选中radio样式
            obj.tr.find('i[class="layui-anim layui-icon"]').trigger("click");
        });
    })
</script>